package view.test;

import java.awt.Color;
import java.awt.Component;
import java.awt.Point;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;
import javax.swing.event.MouseInputListener;

import controller.BankType;
import controller.GameController;
import controller.actions.BinAction;

public class BankMouseInputListener implements MouseInputListener {
	
	private GameController controller;
	private BankType type;
	private Color color;
	private ImageIcon icon;
	private GlassPane glassPane;

	public BankMouseInputListener(GameController controller, BinBank bank, GlassPane pane) {
		this.controller = controller;
		this.type = bank.getBankType();
		this.color = bank.getColor();
		this.icon = bank.getEntityIcon();
		this.glassPane = pane;
	}
	
	@Override
	public void mouseClicked(MouseEvent arg0) {
		
		controller.handleBinClicked(new BinAction(type, color, icon));

	}

	@Override
	public void mouseDragged(MouseEvent arg0) {	
		
		Component component = arg0.getComponent();
		Point glassPanePoint = SwingUtilities.convertPoint(component, arg0.getPoint(), glassPane);
		glassPane.setCursorPoint(glassPanePoint);
		glassPane.repaint();
		controller.handleBinDraggedAction(new BinAction(type, color, icon));
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {	}

	@Override
	public void mouseExited(MouseEvent arg0) {	}

	@Override
	public void mousePressed(MouseEvent arg0) {	}

	@Override
	public void mouseReleased(MouseEvent arg0) { }

	@Override
	public void mouseMoved(MouseEvent arg0) { 
		Component component = arg0.getComponent();
		Point glassPanePoint = SwingUtilities.convertPoint(component, arg0.getPoint(), glassPane);
		glassPane.setCursorPoint(glassPanePoint);
		glassPane.repaint();
	}

}
